package com.example.adapter;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import com.example.resource.City;
import com.example.resource.Province;
import com.yijiu.trb.R;

public class CityAdapter extends BaseExpandableListAdapter {

	private Context context;

	private List<Province> provincesList;

	private Map<Integer, List<City>> cityListMap;

	public CityAdapter(Context context, List<Province> provincesList, Map<Integer, List<City>> cityListMap) {
		this.context = context;
		this.provincesList = provincesList;
		this.cityListMap = cityListMap;
	}

	@Override
	public Object getChild(int arg0, int arg1) {
		// TODO Auto-generated method stub
		return cityListMap.get(arg0).get(arg1);
	}

	@Override
	public long getChildId(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		return childPosition;
	}

	@Override
	public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		convertView = LayoutInflater.from(context).inflate(R.layout.view_city_name, null);
		TextView cityNameTextView = (TextView) convertView.findViewById(R.id.tv_city_adapter_name);
		City city = cityListMap.get(groupPosition).get(childPosition);
		cityNameTextView.setText(city.cityName);
		return convertView;
	}

	@Override
	public int getChildrenCount(int groupPosition) {
		// TODO Auto-generated method stub
		return cityListMap.get(groupPosition).size();
	}

	@Override
	public Object getGroup(int groupPosition) {
		// TODO Auto-generated method stub
		return provincesList.get(groupPosition);
	}

	@Override
	public int getGroupCount() {
		// TODO Auto-generated method stub
		return provincesList.size();
	}

	@Override
	public long getGroupId(int groupPosition) {
		// TODO Auto-generated method stub
		return groupPosition;
	}

	@Override
	public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		convertView = LayoutInflater.from(context).inflate(R.layout.view_province_name, null);
		TextView provinceNameTextView = (TextView) convertView.findViewById(R.id.tv_province_adapter_name);
		Province province = provincesList.get(groupPosition);
		provinceNameTextView.setText(province.provinceName);
		return convertView;
	}

	@Override
	public boolean hasStableIds() {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public boolean isChildSelectable(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		return true;
	}

}
